/**
 * ClienteConverter.java
 *
 * $Id$
 *
 */
package br.com.fatecmococa.converters;

import br.com.fatecmococa.dao.ClienteDAO;
import br.com.fatecmococa.model.Cliente;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
@FacesConverter(value="ClienteConverter")
public class ClienteConverter implements Converter {

    private static final long serialVersionUID = 1L;

    
    
    public ClienteConverter(){
    }

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        if (arg2 != null) {
            ClienteDAO dao = new ClienteDAO();
            return dao.getClientePorNome(arg2);
        }
        return null;
    }
    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        if (arg2 != null) {
            Cliente cliente = (Cliente)arg2;
            return cliente.getNome();
        }
        return null;
    }


}
